package com.mrs.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mrs.entity.Role;
import com.mrs.mapper.RoleMapper;
import com.mrs.service.RoleService;
import com.mrs.utils.SecurityUtils;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * 角色信息表(Role)表服务实现类
 *
 * @author makejava
 * @since 2022-09-10 16:44:16
 */
@Service("roleService")
public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements RoleService {

    /**
     * @description:  查询角色列表
     * @param userId
     * @return: java.util.List<java.lang.String>
     * @author: MR.孙
     * @date: 2022/9/10 17:34
    */
    @Override
    public List<String> selectRolesByUserId(Long userId) {
        //判断是否是管理员,如果是集合直接返回admin
        if(SecurityUtils.isAdmin()){
            List<String> roleKeys = new ArrayList<>();
            roleKeys.add("admin");
            return roleKeys;
        }

        //否则查询用户所具有的角色列表
        return getBaseMapper().selectRoleKeysByUserId(userId);
    }
}
